package Client.GUI;

import Client.logic.ClientIF;
import Server.Message.MessageNewSemester;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JOptionPane;

import java.awt.Component;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class OpenSemesterPanel extends MyJPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public OpenSemesterPanel( ClientIF client) {
		super(PanelType.OPEN_SEMESTER_PANEL, client);
		setLayout(null);
		
		BufferedImage myPic;
		try {
			myPic = ImageIO.read(new File("images"+ File.separator+"open semester.jpg"));
		
			JLabel lblAddClass = new JLabel(new ImageIcon(myPic), JLabel.CENTER);
			lblAddClass.setBounds(35, 0, 482, 99);
			add(lblAddClass);
		
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		JButton btnContinue = new JButton("continue");
		btnContinue.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Object[] options = {"Continue", "Cancel"};
				int n = JOptionPane.showOptionDialog((Component) getClient(),
						"Are you sure you want to continue? ",
								"Alert",
								JOptionPane.YES_NO_OPTION,
								JOptionPane.WARNING_MESSAGE,
								null,
								options,
								options[1]);
				if (n==0) {
				getClient().sendMsgToServer(new MessageNewSemester());
				getClient().swap(new AssignClassToCoursePanel(getClient()));
				}
			}
		});
		btnContinue.setBounds(140, 244, 89, 23);
		add(btnContinue);
		
		JButton btnCancel = new JButton("cancel");
		btnCancel.setBounds(281, 244, 89, 23);
		add(btnCancel);
		
		JLabel lblWarningOpenNew = new JLabel("warning: open new semester make the old one to be read only");
		lblWarningOpenNew.setBounds(89, 138, 460, 14);
		add(lblWarningOpenNew);
		// TODO Auto-generated constructor stub
	}

	@Override
	public MyJPanel pushPanel() {
		return new OpenSemesterPanel(getClient());
	}
}
